package com.demo.controller;


import com.demo.entity.dto.StatisticsDataDto;
import com.demo.entity.enums.UserStatusEnum;
import com.demo.entity.po.CounselorInfo;
import com.demo.entity.query.CounselorInfoQuery;
import com.demo.entity.query.UserInfoQuery;
import com.demo.entity.vo.ResponseVO;
import com.demo.service.CounselorInfoService;
import com.demo.service.UserInfoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class IndexController extends ABaseController{

    @Resource
    private CounselorInfoService counselorInfoService;

    @Resource
    private UserInfoService userInfoService;

    @RequestMapping("/index/getData")
    public ResponseVO getData() {
        CounselorInfoQuery query = new CounselorInfoQuery();
        query.setPageNo(1);
        query.setPageSize(5);
        query.setOrderBy("rating desc");
        List<CounselorInfo> param = counselorInfoService.findListByParam(query);

        StatisticsDataDto statisticsDataDto = new StatisticsDataDto();
        statisticsDataDto.setCounselorInfoList(param);

        UserInfoQuery userInfoQuery = new UserInfoQuery();
        userInfoQuery.setStatus(UserStatusEnum.ENABLE.getStatus());
        Integer count1 = userInfoService.findCountByParam(userInfoQuery);
        statisticsDataDto.setUserCount(count1);

        CounselorInfoQuery counselorInfoQuery=new CounselorInfoQuery();
        counselorInfoQuery.setStatus(UserStatusEnum.ENABLE.getStatus());
        Integer count2 = counselorInfoService.findCountByParam(counselorInfoQuery);
        statisticsDataDto.setCouncelorCount(count2);
        return getSuccessResponseVO(statisticsDataDto);
    }
}
